<?php

declare (strict_types=1);

namespace app\api\controller;

use app\api\model\ActivityLog as ActivityLogModel;
use app\api\service\User as UserService;
use cores\exception\BaseException;
use think\response\Json;

/**
 * 送券活动
 * Class WxPush
 * @package app\api\controller
 */
class Activity extends Controller
{
    /**
     * 新用户注册送现金券
     * @return Json
     * @throws BaseException
     */
    public function regCoupon(): Json
    {
        $model = new ActivityLogModel;
        if ($model->receive(1)) {
            return $this->renderSuccess([], '领取成功');
        }
        return $this->renderError($model->getError() ?: '领取失败');
    }

    /**
     * 检验注册用户是否已送现金券
     * @return Json
     * @throws BaseException
     */
    public function isRegCoupon(): Json
    {
        $model = new ActivityLogModel;
        // 当前用户ID
        $userId = UserService::getCurrentLoginUserId(true);
        if ($model->checkReceive($userId, 1)) {
            $data['status'] = 1;
            $data['message'] = '注册活动已领取';
        }else{
            $data['status'] = 0;
            $data['message'] = '注册活动未领取';
        }
        return $this->renderSuccess($data);
    }
}
